﻿using System.Data;
using System.Data.SqlClient;

namespace BitsOfJoy.Data
{
    public class SqlProcedure : ISqlProcedure
    {
        public string ProcedureName { get; private set; }
        private SqlConnection Connection { get; set; }
        private SqlCommand Command { get; set; }
        //public List<string> Parameters { get; set; }

        public SqlProcedure( string procedureName )
        {
            ProcedureName = procedureName;
            Connection = new SqlConnection("server=localhost;uid=sa;pwd=password;database=master;");
            Command = new SqlCommand(ProcedureName, Connection);
        }

        public SqlDataReader ExecuteReader()
        {
            Command.Connection.Open();
            return Command.ExecuteReader(CommandBehavior.CloseConnection);
        }

        public object ExecuteScalar()
        {
            Command.Connection.Open();
            return Command.ExecuteScalar();
        }

        public void ExecuteNonQuery()
        {
            Command.Connection.Open();
            Command.ExecuteNonQuery();
        }
    }
}